package com.hzbank.juc.wait;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2023/12/21 - 18:59
 */
@Slf4j
public class Sleep01 {
    static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {

        new Thread(()->{
            synchronized (lock){
                log.debug("t1获得锁");
                try {
//                    Thread.sleep(20000);
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"t1").start();

        TimeUnit.SECONDS.sleep(1);
        synchronized (lock){
            log.debug("main线程获得锁");
        }
    }
}
